package likou.xiaomazhixing.one;

import java.util.HashSet;
import java.util.Scanner;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/09/06 15:01
 */
public class _001 {
    static int[][] positions = new int[][]{
            {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}
    };

    public static void main(String[] args) throws InterruptedException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[][] nums = new int[101][101];
        HashSet<Integer> set = new HashSet<>();
        nums[50][50] = n;
        if (n <= 8) {
            set.add(getHash(50, 50));//存的是i、j的哈希
        }
        //计算结果
        while (set.size() > 0) {
            HashSet<Integer> set2 = new HashSet<>();
            for (int hash : set) {
                int[] ij = getij(hash);
                int num = nums[ij[0]][ij[1]];
                while (num > 0) {
                    int max = num >= 8 ? 8 : num;
                    num -= 8;
                    for (int i = 0; i < max; i++) {
                        int nowI = ij[0] + positions[i][0];
                        int nowJ = ij[1] + positions[i][1];
                        nums[nowI][nowJ]++;
                        if (nums[nowI][nowJ] >= 8) set2.add(getHash(nowI, nowJ));
                    }
                }
                nums[ij[0]][ij[1]] = 0;
            }
            set = set2;
        }
        while (q > 0) {
            q--;
            int lx = sc.nextInt();
            int ly = sc.nextInt();
            int rx = sc.nextInt();
            int ry = sc.nextInt();
            int res = 0;
            for (int i=lx+50;i<=rx+50;i++){
                for (int j=ly+50;j<=ry+50;j++){
                    res += nums[i][j];
                }
            }
            System.out.println(res);
        }
    }

    public static int[] getij(int hash) {
        return new int[]{hash / 1000, hash % 1000};
    }

    public static int getHash(int i, int j) {
        return i * 1000 + j;
    }
}
